package com.xgk.boot.module.core.dal.mapper.truck;

import com.xgk.boot.framework.mybatis.core.mapper.BaseMapperX;
import com.xgk.boot.module.core.dal.entity.truck.TruckOrdersDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 卡车订单主表 Mapper接口
 */
@Mapper
public interface TruckOrdersMapper extends BaseMapperX<TruckOrdersDO> {

    @Select({
            "<script>",
            "SELECT ",
            "   DATE(create_time) AS order_date, ",
            "   COUNT(*) AS order_count ",
            "FROM ",
            "   truck_orders ",
            "WHERE ",
            "   create_time >= DATE_SUB(CURDATE(), INTERVAL 29 DAY) ",
            "   <if test='customCode != null'>",
            "   AND customer_code = #{customCode}",
            "   </if>",
            "GROUP BY ",
            "   DATE(create_time) ",
            "ORDER BY ",
            "   order_date ASC",
            "</script>"
    })
    List<Map<String, Object>> getLast30DaysOrderStats(@Param("customCode") String customCode);


}